package com.wut.clock.factory.number;

import com.wut.clock.common.util.RedisKeyUtil;
import com.wut.clock.mongo.repository.FollowRepository;
import com.wut.clock.vo.portal.ArticleCountVo;
import com.wut.clock.vo.portal.CommentCountVo;
import com.wut.clock.vo.portal.UserCountVo;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;


/**
 * @author ZYH
 * @unit D9Lab
 * @description 获取用户的粉丝数
 * @date 2022/6/13 15:33
 */
public class UserCount implements Number {

    @Resource
    private FollowRepository followRepository;

    @Resource
    private RedisTemplate redisTemplate;


    @Override
    public UserCountVo countUserNumber(Integer userId) {
        //获取粉丝数
        int followerCount = followRepository.countByFolloweeUserId(userId);
        //获取关注数
        int followeeCount = followRepository.countByFollowerUserId(userId);
        //获取获赞数
        String userLikeKey = RedisKeyUtil.getUserLikeKey(userId);
        int likeCount = (int)redisTemplate.opsForValue().get(userLikeKey);
        UserCountVo userCountVo = new UserCountVo();
        userCountVo.setFollowerCount(followerCount);
        userCountVo.setFolloweeCount(followeeCount);
        userCountVo.setLikeCount(likeCount);
        return userCountVo;
    }

    @Override
    public ArticleCountVo countArticleNumber(Integer articleId) {
        return null;
    }

    @Override
    public CommentCountVo countCommentNumber(Integer commentId) {
        return null;
    }
}
